package cn.youruan.demo.controller;

import cn.youruan.demo.common.R;
import cn.youruan.demo.domain.Hobby;
import cn.youruan.demo.domain.Lottery;
import cn.youruan.demo.domain.User;
import cn.youruan.demo.dto.HobbyDto;
import cn.youruan.demo.dto.UserDto;
import cn.youruan.demo.service.IHobbyService;
import cn.youruan.demo.service.ILotteryService;
import cn.youruan.demo.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/publicInformation")
@Slf4j
public class PublicInformationController {
    @Autowired
    private IUserService userService;

    @Autowired
    private IHobbyService hobbyService;

    @Autowired
    private ILotteryService lotteryService;


    /**
     * 热门爱好排序
     * @return
     */
    @GetMapping("/hotHobby")
    public R<List<HobbyDto>> hotHobby() {
        return R.success(hobbyService.sortHotHobby());
    }

    /**
     * 爱好广泛用户排行
     * @return
     */
    @GetMapping("/hobbyMaxUser")
    public R<List<UserDto>> hobbyMaxUser() {
        return  R.success(userService.sortByHobbyMaxUser());
    }

    /**
     * 本月内总获得积分排行
     * @return
     */
    @GetMapping("/sortByCount")
    public R<List<User>> sortByCount() {
        return R.success(userService.sortByCount());
    }

    /**
     * 活跃用户列表
     * @return
     */
    @GetMapping("/activeUser")
    public R<List<Lottery>> activeUser() {
        LocalDateTime endTime = LocalDateTime.now();
        LocalDateTime startTime = endTime.plusDays(-3);
        return R.success(lotteryService.sortByActiveUser(startTime,endTime));
    }
}
